package pe.sonrisas.tools.view;

import Complementos.Conexion_BD;
import Complementos.Validar;
import Complementos.Visual;
import Control.ControlFotoPaciente;
import Control.ControlPaciente;
import Control.ControlPersona;
import Control.ControlUbigeo;
import java.awt.Image;
import java.sql.ResultSet;
import java.util.ArrayList;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;

/*
 * frmRegistrarPaciente.java
 *
 * Created on 01/08/2011, 11:35:35 AM. Programador : Diego Alvarado / Bruno
 * Alvarado . Descripcion : Formulario de registro de paciente . Última
 * modificación : 19/08/2011 , 16:00:00 hs Observaciones :  *
 * Modificaciones : * La tabla de reporte, ahora muestra los datos de manera
 * correcta al buscar los pacientes. Se borró el código de validaciones de este
 * frm, y ahora se accede a las validaciones de la clase Validar.
 *
 * Modificaciones Bruno 19/8/2011 17:40 ARG : -
 *
 * cambie formato los txt de fechaNac y primera visita de short a medium para q
 * el metodo edad pueda calcular la edad -se agrego un evento cuando focusea en
 * fecNacmiento para q al modificar actualize la edad (la edad se refleja cuando
 * el focus sale de fechaNac) -Fecha de Alta y nacimiento pasa a estar
 * deshabilitado (arreglado con el efecto) -se cambio la etiketa de Primera
 * visita a Fecha de Alta -se arreglo el color del boton modificar -ahora
 * deshabilita los campos si se selecciona otro paciente de la table cuando
 * antes se habia picado en modificar datos en otro paciente -se cambio las
 * imagenes al paquete "media"
 *
 *
 * Modificaciones Diego 19/08/2011 , 02:24 PER : -
 *
 * Se agrega el btnReservarCita , este envía a frmReservaCita el código del
 * paciente y hace la búsqueda para que al abrirse la reserva, se encuentre el
 * código y los datos del paciente ya ingresados en el formulario.
 *
 *
 * *Modificaciones Bruno 21/08 21.05 - se agrego icono al programa y se parcho
 * la ruta de las imagenes 24.00 - ahora busqueda valida q no este vacio 22/08
 * 23.21 -se validan los campos obligatorios al ser modificados 22/8/ 24.00 - se
 * agrego el aspecto mac
 *
 *
 */
public class probando extends javax.swing.JFrame {

    /**
     * Creates new form frmConsultarPaciente
     */
    private ImageIcon etiquetaImagen;
    String rutaOrigen;
    Conexion_BD co = new Conexion_BD();
    ResultSet rs = null;
    Validar validar = new Validar();
    //xxxxxxx   frmReservaCita reserva = new frmReservaCita(this, true);
    ArrayList<ArrayList> listado = new ArrayList<ArrayList>();
    static private probando objeto = null;

    public probando() {
        initComponents();
        this.setIconImage(new ImageIcon(getClass().getResource("/Media/logo1.png")).getImage());
    }

    static public probando getInstancia() {
        if (objeto == null) {
            objeto = new probando();
        }
        return objeto;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        panelPaciente = new javax.swing.JPanel();
        panelFoto1 = new javax.swing.JPanel();
        lblFoto = new javax.swing.JLabel();
        txtCodigoPaciente = new javax.swing.JTextField();
        lblCodPaciente1 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtNombres = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        txtApellidoPaterno = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        txtDni = new javax.swing.JTextField();
        jLabel25 = new javax.swing.JLabel();
        txtNacionalidad = new javax.swing.JTextField();
        txtDireccion = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        txtTel = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        txtCelular = new javax.swing.JTextField();
        jLabel28 = new javax.swing.JLabel();
        jLabel29 = new javax.swing.JLabel();
        txtOcupacion = new javax.swing.JTextField();
        jLabel30 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtAntecedentes = new javax.swing.JTextArea();
        jLabel31 = new javax.swing.JLabel();
        txtRecomendado = new javax.swing.JTextField();
        btnModificar = new javax.swing.JButton();
        btnConsulta = new javax.swing.JButton();
        txtEdad = new javax.swing.JTextField();
        jLabel32 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        jLabel34 = new javax.swing.JLabel();
        comboGenero = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        btnCambiarFoto = new javax.swing.JButton();
        btnEliminarFoto = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        comboGrupo = new javax.swing.JComboBox();
        txtFechaNac = new datechooser.beans.DateChooserCombo();
        txtFechaAlta = new datechooser.beans.DateChooserCombo();
        btnReservarCita = new javax.swing.JButton();
        btnVerOdontograma = new javax.swing.JButton();
        comboDeptos = new javax.swing.JComboBox();
        comboProvincias = new javax.swing.JComboBox();
        comboDistrito = new javax.swing.JComboBox();
        txtEmail = new javax.swing.JTextField();
        btnEliminarPaciente = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        txtApellidoMaterno = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("..::  Sonrisas Tools :..    Buscar paciente");
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(204, 204, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 153)), "Buscar paciente", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tunga", 0, 24), new java.awt.Color(255, 255, 153))); // NOI18N

        jTabbedPane1.setBackground(new java.awt.Color(204, 204, 255));

        panelPaciente.setBackground(new java.awt.Color(204, 204, 255));

        panelFoto1.setBackground(new java.awt.Color(204, 204, 255));
        panelFoto1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 153)), "Foto"));

        lblFoto.setAutoscrolls(true);

        javax.swing.GroupLayout panelFoto1Layout = new javax.swing.GroupLayout(panelFoto1);
        panelFoto1.setLayout(panelFoto1Layout);
        panelFoto1Layout.setHorizontalGroup(
            panelFoto1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFoto1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblFoto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        panelFoto1Layout.setVerticalGroup(
            panelFoto1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFoto1Layout.createSequentialGroup()
                .addComponent(lblFoto, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
                .addContainerGap())
        );

        txtCodigoPaciente.setEditable(false);

        lblCodPaciente1.setText("Código paciente:");

        jLabel10.setText("Nombres:");

        txtNombres.setEditable(false);
        txtNombres.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNombresKeyPressed(evt);
            }
        });

        jLabel14.setText("Apellido Paterno:");

        txtApellidoPaterno.setEditable(false);
        txtApellidoPaterno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtApellidoPaternoKeyPressed(evt);
            }
        });

        jLabel15.setText("DNI:");

        txtDni.setEditable(false);
        txtDni.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtDniKeyPressed(evt);
            }
        });

        jLabel25.setText("Nacionalidad:");

        txtNacionalidad.setEditable(false);
        txtNacionalidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNacionalidadKeyPressed(evt);
            }
        });

        txtDireccion.setEditable(false);

        jLabel16.setText("Dirección:");

        jLabel22.setText("Departamento:");

        jLabel23.setText("Email:");

        jLabel26.setText("Provincia:");

        txtTel.setEditable(false);
        txtTel.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtTelKeyPressed(evt);
            }
        });

        jLabel17.setText("Teléfono:");

        jLabel27.setText("Celular:");

        txtCelular.setEditable(false);
        txtCelular.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtCelularKeyPressed(evt);
            }
        });

        jLabel28.setText("Distrito:");

        jLabel29.setText("Ocupación:");

        txtOcupacion.setEditable(false);
        txtOcupacion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtOcupacionKeyPressed(evt);
            }
        });

        jLabel30.setText("Antecedentes:");

        txtAntecedentes.setColumns(20);
        txtAntecedentes.setEditable(false);
        txtAntecedentes.setRows(5);
        jScrollPane3.setViewportView(txtAntecedentes);

        jLabel31.setText("Recomendado por:");

        txtRecomendado.setEditable(false);

        btnModificar.setText("Modificar datos");
        btnModificar.setEnabled(false);
        btnModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificarActionPerformed(evt);
            }
        });

        btnConsulta.setText("Registrar consulta");
        btnConsulta.setEnabled(false);

        txtEdad.setEditable(false);
        txtEdad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtEdadKeyPressed(evt);
            }
        });

        jLabel32.setText("Edad:");

        jLabel33.setText("Fecha Nac:");

        jLabel34.setText("Género:");

        comboGenero.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "M", "F" }));
        comboGenero.setEnabled(false);

        jLabel1.setText("Fecha Alta:");

        btnCambiarFoto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Media/cam.png"))); // NOI18N
        btnCambiarFoto.setEnabled(false);
        btnCambiarFoto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCambiarFotoActionPerformed(evt);
            }
        });

        btnEliminarFoto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Media/btnEliminar.png"))); // NOI18N
        btnEliminarFoto.setEnabled(false);
        btnEliminarFoto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarFotoActionPerformed(evt);
            }
        });

        jLabel2.setText("Grupo:");

        comboGrupo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Adulto", "Niño" }));
        comboGrupo.setEnabled(false);

        txtFechaNac.setEnabled(false);
        txtFechaNac.setBehavior(datechooser.model.multiple.MultyModelBehavior.SELECT_SINGLE);
        txtFechaNac.addSelectionChangedListener(new datechooser.events.SelectionChangedListener() {
            public void onSelectionChange(datechooser.events.SelectionChangedEvent evt) {
                txtFechaNacOnSelectionChange(evt);
            }
        });

        txtFechaAlta.setEnabled(false);
        txtFechaAlta.setBehavior(datechooser.model.multiple.MultyModelBehavior.SELECT_SINGLE);

        btnReservarCita.setText("Reservar cita");
        btnReservarCita.setEnabled(false);
        btnReservarCita.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReservarCitaActionPerformed(evt);
            }
        });

        btnVerOdontograma.setText("Ver odontograma");
        btnVerOdontograma.setEnabled(false);
        btnVerOdontograma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVerOdontogramaActionPerformed(evt);
            }
        });

        comboDeptos.setEditable(true);
        comboDeptos.setEnabled(false);
        comboDeptos.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboDeptosItemStateChanged(evt);
            }
        });

        comboProvincias.setEditable(true);
        comboProvincias.setEnabled(false);
        comboProvincias.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboProvinciasItemStateChanged(evt);
            }
        });

        comboDistrito.setEditable(true);
        comboDistrito.setEnabled(false);

        txtEmail.setEditable(false);

        btnEliminarPaciente.setText("Eliminar Paciente");
        btnEliminarPaciente.setEnabled(false);
        btnEliminarPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarPacienteActionPerformed(evt);
            }
        });

        jLabel3.setText("Apellido Materno:");

        txtApellidoMaterno.setEditable(false);

        javax.swing.GroupLayout panelPacienteLayout = new javax.swing.GroupLayout(panelPaciente);
        panelPaciente.setLayout(panelPacienteLayout);
        panelPacienteLayout.setHorizontalGroup(
            panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPacienteLayout.createSequentialGroup()
                .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPacienteLayout.createSequentialGroup()
                        .addGap(12, 12, Short.MAX_VALUE)
                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPacienteLayout.createSequentialGroup()
                                .addComponent(lblCodPaciente1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtCodigoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPacienteLayout.createSequentialGroup()
                                .addComponent(btnCambiarFoto)
                                .addGap(18, 18, 18)
                                .addComponent(btnEliminarFoto, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(panelPacienteLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(panelFoto1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnEliminarPaciente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPacienteLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelPacienteLayout.createSequentialGroup()
                                .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(panelPacienteLayout.createSequentialGroup()
                                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jLabel16)
                                            .addComponent(jLabel27)
                                            .addComponent(jLabel23)
                                            .addComponent(jLabel10))
                                        .addGap(16, 16, 16))
                                    .addGroup(panelPacienteLayout.createSequentialGroup()
                                        .addComponent(jLabel25)
                                        .addGap(18, 18, 18)))
                                .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtEmail)
                                    .addComponent(txtCelular)
                                    .addComponent(txtDireccion)
                                    .addComponent(txtNacionalidad)
                                    .addComponent(txtNombres, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE))
                                .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPacienteLayout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel15, javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jLabel22, javax.swing.GroupLayout.Alignment.TRAILING)))
                                    .addGroup(panelPacienteLayout.createSequentialGroup()
                                        .addGap(40, 40, 40)
                                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel3)
                                            .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel26)
                                                .addComponent(jLabel14))))))
                            .addGroup(panelPacienteLayout.createSequentialGroup()
                                .addComponent(jLabel30)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel28, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelPacienteLayout.createSequentialGroup()
                                .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtDni)
                                    .addComponent(txtApellidoPaterno)
                                    .addComponent(txtRecomendado)
                                    .addComponent(comboDeptos, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(comboProvincias, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(comboDistrito, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(txtApellidoMaterno))
                                .addGap(18, 18, 18)
                                .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel17)
                                    .addComponent(jLabel29)
                                    .addComponent(jLabel33)
                                    .addComponent(jLabel32)
                                    .addComponent(jLabel34)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
                            .addGroup(panelPacienteLayout.createSequentialGroup()
                                .addComponent(jLabel31)
                                .addGap(140, 140, 140)))
                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(txtFechaAlta, 0, 0, Short.MAX_VALUE)
                                .addComponent(txtFechaNac, 0, 0, Short.MAX_VALUE)
                                .addComponent(txtTel, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtOcupacion, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                                .addComponent(txtEdad, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(comboGenero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(comboGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(104, 104, 104))
                    .addGroup(panelPacienteLayout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(btnModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(47, 47, 47)
                        .addComponent(btnConsulta, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(29, 29, 29)
                        .addComponent(btnVerOdontograma, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnReservarCita, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        panelPacienteLayout.setVerticalGroup(
            panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPacienteLayout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panelPacienteLayout.createSequentialGroup()
                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNombres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtApellidoPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14)
                            .addComponent(jLabel10)
                            .addComponent(jLabel17)
                            .addComponent(txtTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtCodigoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblCodPaciente1))
                        .addGap(18, 18, 18)
                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNacionalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel25)
                            .addComponent(jLabel29)
                            .addComponent(txtOcupacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3)
                            .addComponent(txtApellidoMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel16)
                                .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel33)
                                .addComponent(jLabel15)
                                .addComponent(txtDni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(txtFechaNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel32)
                                .addComponent(txtEdad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel23)
                                .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel22)
                                .addComponent(comboDeptos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel27)
                            .addComponent(jLabel34)
                            .addComponent(comboGenero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel26)
                            .addComponent(comboProvincias, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(panelFoto1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPacienteLayout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(btnCambiarFoto, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                            .addComponent(btnEliminarFoto, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(7, 7, 7)
                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel30)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(panelPacienteLayout.createSequentialGroup()
                                .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel31))
                                .addGap(18, 18, 18)
                                .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel2)
                                    .addComponent(comboGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtRecomendado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(txtFechaAlta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnModificar)
                            .addComponent(btnConsulta)
                            .addComponent(btnEliminarPaciente)
                            .addComponent(btnVerOdontograma)
                            .addComponent(btnReservarCita))
                        .addGap(53, 53, 53))
                    .addGroup(panelPacienteLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(panelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel28)
                            .addComponent(comboDistrito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())))
        );

        jTabbedPane1.addTab("Datos paciente", panelPaciente);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 935, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 469, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(165, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnEliminarPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarPacienteActionPerformed
        boolean ok = cambiarActivo(Integer.parseInt(txtCodigoPaciente.getText()));
        if (ok == true) {
            JOptionPane.showMessageDialog(this, "Se produjo la  actualizacion de baja");
        } else {
            JOptionPane.showMessageDialog(this, "Se produjo un error al actualizar los datos", "Error al actualizar", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnEliminarPacienteActionPerformed

    private void comboProvinciasItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboProvinciasItemStateChanged
        comboDistrito.removeAllItems();
        int codD = comboDeptos.getSelectedIndex();
        int codP = comboProvincias.getSelectedIndex();
        cargarComboDistritos(codD, codP);
    }//GEN-LAST:event_comboProvinciasItemStateChanged

    private void comboDeptosItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboDeptosItemStateChanged
        comboProvincias.removeAllItems();
        int cod = comboDeptos.getSelectedIndex();
        cargarComboProvincias(cod);
    }//GEN-LAST:event_comboDeptosItemStateChanged

    private void btnVerOdontogramaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVerOdontogramaActionPerformed

        Icon foto = lblFoto.getIcon();
        //frmOdontotab fr=new frmOdontotab(txtNombres.getText(), txtApellidos.getText(), txtDireccion.getText(), txtTel.getText(),comboDistrito.getSelectedItem().toString(),txtCodigoPaciente.getText());
        //xxxxx    frmOdontotab fr = frmOdontotab.getInstancia(txtNombres.getText(), txtApellidos.getText(), txtDireccion.getText(), txtTel.getText(), comboDistrito.getSelectedItem().toString(),txtCodigoPaciente.getText());
        //xxxxx    fr.setVisible(true);
    }//GEN-LAST:event_btnVerOdontogramaActionPerformed

    private void btnReservarCitaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReservarCitaActionPerformed
//activar despues ojoooooooooooooooo
//    reserva.setearCodigo(txtCodigoPaciente.getText());
//    reserva.buscarPaciente();
//    reserva.setVisible(true);
    }//GEN-LAST:event_btnReservarCitaActionPerformed

    private void txtFechaNacOnSelectionChange(datechooser.events.SelectionChangedEvent evt) {//GEN-FIRST:event_txtFechaNacOnSelectionChange
        // calcula edad
        txtEdad.setText("" + validar.calcularEdad(txtFechaNac.getText()));
    }//GEN-LAST:event_txtFechaNacOnSelectionChange

    private void btnEliminarFotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarFotoActionPerformed
        cargarFotoDefecto();
    }//GEN-LAST:event_btnEliminarFotoActionPerformed

    private void btnCambiarFotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCambiarFotoActionPerformed
        cambiarImagen();
    }//GEN-LAST:event_btnCambiarFotoActionPerformed

    private void txtEdadKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtEdadKeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER) {
            txtCelular.requestFocus();
        }
    }//GEN-LAST:event_txtEdadKeyPressed

    private void btnModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarActionPerformed
        if (btnModificar.getText().equals("Modificar datos")) {
            habilitarCampos(true);
        } else {
            if (camposObligatorios()) {
                boolean modifico = false;
                boolean modifico2 = false;
                boolean cargofoto = false;

                ControlUbigeo ubigeo = new ControlUbigeo();
                ControlPersona persona = new ControlPersona();
                ControlPaciente paciente = new ControlPaciente();

                int id_ubigeo = ubigeo.dameIdUbigeo(comboDeptos.getSelectedIndex() + 1, comboProvincias.getSelectedIndex() + 1, comboDistrito.getSelectedIndex() + 1);
                modifico = persona.editarPersona(Integer.parseInt(txtCodigoPaciente.getText()), txtNombres.getText(), txtApellidoPaterno.getText(), txtApellidoMaterno.getText(), txtDni.getText(), txtNacionalidad.getText(), txtDireccion.getText(), txtEmail.getText(), txtTel.getText(), txtCelular.getText(), validar.cambiarFormatoFechaParaBD(txtFechaNac.getText()), comboGenero.getSelectedItem().toString().charAt(0), id_ubigeo);
                modifico2 = paciente.editarPaciente(Integer.parseInt(txtCodigoPaciente.getText()), txtAntecedentes.getText(), txtOcupacion.getText(), txtRecomendado.getText(), comboGrupo.getSelectedItem().toString().charAt(0), validar.cambiarFormatoFechaParaBD(txtFechaAlta.getText()));

                //comboGrupo.getSelectedItem().toString().charAt(0),validar.cambiarFormatoFechaParaBD(txtFechaAlta.getText())

                if (!(rutaOrigen.equals("NoFoto"))) {
                    ControlFotoPaciente controlFoto = new ControlFotoPaciente();
                    cargofoto = controlFoto.modificarFoto(txtCodigoPaciente.getText(), rutaOrigen);
                }



                if (modifico && modifico2) {
                    JOptionPane.showMessageDialog(this, "Se actualizaron los datos del paciente", "Paciente actualizado", JOptionPane.INFORMATION_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(this, "Se produjo un error al actualizar los datos", "Error al actualizar", JOptionPane.ERROR_MESSAGE);
                }


                if (!(rutaOrigen.equals("NoFoto"))) {
                    if (cargofoto) {
                        JOptionPane.showMessageDialog(this, "Se modificó la foto bien piola");
                    } else {
                        JOptionPane.showMessageDialog(this, "Error");
                    }
                }

                habilitarCampos(false);
                btnModificar.setText("Modificar datos");
            }

        }
    }//GEN-LAST:event_btnModificarActionPerformed

    private void txtOcupacionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtOcupacionKeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER) {
            txtDireccion.requestFocus();
        }
    }//GEN-LAST:event_txtOcupacionKeyPressed

    private void txtCelularKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCelularKeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER) {
            if (validar.validarNro(txtTel.getText())) {
                txtEmail.requestFocus();
            } else {
                JOptionPane.showMessageDialog(this, "El celular sólo debe contener numeros", "Error", JOptionPane.ERROR_MESSAGE);
                txtCelular.requestFocus();
                txtCelular.selectAll();
            }
        }
    }//GEN-LAST:event_txtCelularKeyPressed

    private void txtTelKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTelKeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER) {
            if (validar.validarNro(txtTel.getText())) {
                txtNacionalidad.requestFocus();
            } else {
                JOptionPane.showMessageDialog(this, "El teléfono sólo debe contener numeros", "Error", JOptionPane.ERROR_MESSAGE);
                txtTel.requestFocus();
                txtTel.selectAll();
            }
        }
    }//GEN-LAST:event_txtTelKeyPressed

    private void txtNacionalidadKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNacionalidadKeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER) {
            if (validar.validarTexto(txtNacionalidad.getText())) {
                txtDni.requestFocus();
            } else {
                JOptionPane.showMessageDialog(this, "La nacionalidad no debe contener numeros/símbolos", "Error", JOptionPane.ERROR_MESSAGE);
                txtNacionalidad.requestFocus();
                txtNacionalidad.selectAll();
            }
        }
    }//GEN-LAST:event_txtNacionalidadKeyPressed

    private void txtDniKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDniKeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER) {
            if (validar.validarNro(txtDni.getText())) {
                txtOcupacion.requestFocus();
            } else {
                JOptionPane.showMessageDialog(this, "El DNI sólo debe contener numeros", "Error", JOptionPane.ERROR_MESSAGE);
                txtDni.requestFocus();
                txtDni.selectAll();
            }
        }
    }//GEN-LAST:event_txtDniKeyPressed

    private void txtApellidoPaternoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtApellidoPaternoKeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER) {
            if (validar.esVacio(txtApellidoPaterno.getText())) {
                JOptionPane.showMessageDialog(this, "Debe ingresar apellidos", "Campo obligatorio", JOptionPane.ERROR_MESSAGE);
                txtApellidoPaterno.requestFocus();
            } else if (validar.validarTexto(txtApellidoPaterno.getText())) {
                txtTel.requestFocus();
            } else {
                JOptionPane.showMessageDialog(this, "El apellido no debe contener numeros/símbolos", "Error", JOptionPane.ERROR_MESSAGE);
                txtApellidoPaterno.requestFocus();
                txtApellidoPaterno.selectAll();
            }
        }
    }//GEN-LAST:event_txtApellidoPaternoKeyPressed

    private void txtNombresKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombresKeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER) {
            if (validar.esVacio(txtNombres.getText())) {
                JOptionPane.showMessageDialog(this, "Debe ingresar un nombre", "Campo obligatorio", JOptionPane.ERROR_MESSAGE);
                txtNombres.requestFocus();
            } else if (validar.validarTexto(txtNombres.getText())) {
                txtApellidoPaterno.requestFocus();
            } else {
                JOptionPane.showMessageDialog(this, "El nombre no debe contener numeros/símbolos", "Error", JOptionPane.ERROR_MESSAGE);
                txtNombres.requestFocus();
                txtNombres.selectAll();
            }
        }
    }//GEN-LAST:event_txtNombresKeyPressed
    
    
    
    
    public boolean cambiarActivo(int codigo){
    boolean cambio=false;
    ControlPaciente control = new ControlPaciente();
    cambio = control.cambiarActivo(codigo);
    return cambio;
    }
    
    /*
    public void buscarPaciente() {

        int opcion = comboBusqueda.getSelectedIndex();
        String busqueda = "";

        if (opcion == 0) //busqueda = validar.agregarCerosYNumeroAIncrementar(txtBusqueda.getText(), 0);
        {
            busqueda = txtBusqueda.getText();
        } else {
            busqueda = txtBusqueda.getText();
        }

        ControlPaciente control = new ControlPaciente();
        listado = control.listarPaciente(opcion, busqueda);


        int fila = 0;
        for (int i = 0; i < listado.size(); i++) {
            tblReporte.setValueAt(listado.get(i).get(0), fila, 0);
            tblReporte.setValueAt(listado.get(i).get(1), fila, 1);
            tblReporte.setValueAt(listado.get(i).get(2), fila, 2);
            tblReporte.setValueAt(listado.get(i).get(3), fila, 3);
            tblReporte.setValueAt(listado.get(i).get(4), fila, 4);
            tblReporte.setValueAt(validar.cambiarFormatoFecha(listado.get(i).get(10).toString()), fila, 5);
            tblReporte.setValueAt(listado.get(i).get(8), fila, 6);
            tblReporte.setValueAt(listado.get(i).get(9), fila, 7);
            tblReporte.setValueAt(listado.get(i).get(11), fila, 8);
            tblReporte.setValueAt(listado.get(i).get(16), fila, 9);
            fila++;
        }


        if (listado.size() == 0) {
            JOptionPane.showMessageDialog(this, "No se encontraron coincidencias", "Error", JOptionPane.ERROR_MESSAGE);
            limpiarTabla();
            limpiarVentana();
            habilitarCampos(false);
        }
    }
*/

    /*
     * CARGA LA FOTO SELECCIONADA POR EL USUARIO
     */
    public void cambiarImagen() {
        JFileChooser jf = new JFileChooser();
        jf.setDialogTitle("Seleccione una foto");
        jf.setAcceptAllFileFilterUsed(false);
        jf.setFileFilter(new FileNameExtensionFilter("jpg, png, gif", "jpg", "png", "gif"));
        int sel = jf.showOpenDialog(null);

        if (sel == JFileChooser.APPROVE_OPTION) {
            rutaOrigen = jf.getSelectedFile().getAbsolutePath();
            this.etiquetaImagen = new ImageIcon(rutaOrigen);
            Icon icono = new ImageIcon(etiquetaImagen.getImage().getScaledInstance(lblFoto.getWidth(), lblFoto.getHeight(), Image.SCALE_DEFAULT));
            lblFoto.setIcon(icono);
        }
    }


    /*
     * Método que carga por defecto una cruz , indicando que no hay foto cargada
     * para el paciente
     */
    public void cargarFotoDefecto() {
        rutaOrigen = "NoFoto";
        ImageIcon imagenes = new ImageIcon();
        imagenes = new ImageIcon(getClass().getResource("/Media/nofoto2.jpg"));
        Icon icono = new ImageIcon(imagenes.getImage().getScaledInstance(lblFoto.getWidth(), lblFoto.getHeight(), Image.SCALE_DEFAULT));
        lblFoto.setIcon(icono);
    }

    /*
     * Muestra en las cajas de texto de la pestaña 'Datos Paciente' , todos los
     * datos del paciente seleccionado en la tabla reporte.
     */
    public void mostrarDatos(ArrayList<ArrayList> v) {


        txtCodigoPaciente.setText("" + v.get(0).get(0).toString());
        txtNombres.setText("" + v.get(0).get(1).toString());
        txtApellidoPaterno.setText("" + v.get(0).get(2).toString());
        txtApellidoMaterno.setText("" + v.get(0).get(3).toString());
        txtDni.setText("" + v.get(0).get(4));
        txtNacionalidad.setText("" + v.get(0).get(5));
        txtDireccion.setText("" + v.get(0).get(6));

        txtEmail.setText("" + v.get(0).get(7));
        txtTel.setText("" + v.get(0).get(8));
        txtCelular.setText("" + v.get(0).get(9));


        //CARGAR COMBOS DE UBIGEO
        ControlUbigeo controlUbi = new ControlUbigeo();
        ArrayList<ArrayList> ubicacion = controlUbi.dameUbicacion(Integer.parseInt("" + v.get(0).get(12)));

        cargarComboDeptos();
        comboDeptos.setSelectedIndex(Integer.parseInt(ubicacion.get(0).get(0).toString()) - 1);
        comboProvincias.setSelectedIndex(Integer.parseInt(ubicacion.get(0).get(1).toString()) - 1);
        comboDistrito.setSelectedIndex(Integer.parseInt(ubicacion.get(0).get(2).toString()) - 1);

               
        String unString = "" + v.get(0).get(10);
        txtFechaNac.setEnabled(true);
        txtFechaNac.setText(validar.cambiarFormatoFecha(unString));
        txtFechaNac.setEnabled(false);

        txtEdad.setText("" + validar.calcularEdad(validar.cambiarFormatoFecha(unString)));


        txtAntecedentes.setText("" + v.get(0).get(13));
        txtOcupacion.setText("" + v.get(0).get(14));
        txtRecomendado.setText("" + v.get(0).get(15));
        comboGenero.setSelectedItem("" + v.get(0).get(11));

        if (v.get(0).get(16).equals("A")) {
            comboGrupo.setSelectedIndex(0);
        } else {
            comboGrupo.setSelectedIndex(1);
        }

        ControlFotoPaciente control = new ControlFotoPaciente();
        Image fotoPaciente = control.cargarFoto(txtCodigoPaciente.getText());
        if (!(fotoPaciente == null)) {
            cargarFoto(fotoPaciente);
        } else {
            cargarFotoDefecto();
        }

        // rutaOrigen = ""+v.get(0).elementAt(19);



        txtFechaAlta.setEnabled(true);
        txtFechaAlta.setText(validar.cambiarFormatoFecha("" + v.get(0).get(17)));
        txtFechaAlta.setEnabled(false);
    }

    /*
     * BORRA LOS DATOS DE LA PESTAÑA 'DATOS PACIENTE'
     */
    public void limpiarVentana() {
        txtNombres.setText("");
        txtApellidoPaterno.setText("");
        txtDni.setText("");
        txtNacionalidad.setText("");
        txtDireccion.setText("");
        //txtDistrito.setText("");
        //txtProvincia.setText("");
        //txtDepartamento.setText("");
        txtTel.setText("");
        txtCelular.setText("");
        txtEdad.setText("");
        txtEmail.setText("");
        txtOcupacion.setText("");
        txtAntecedentes.setText("");
        txtRecomendado.setText("");
        comboGenero.setSelectedIndex(0);
        txtCodigoPaciente.setText("");
        cargarFotoDefecto();
        btnModificar.setEnabled(false);
        btnConsulta.setEnabled(false);
    }

    /*
     * HABILITA LOS CAMPOS PARA QUE SE PUEDA REALIZAR UNA MODIFICACIÓN EN LA
     * PESTAÑA 'DATOS PACIENTE'
     */
    public void habilitarCampos(boolean habilitar) {
        txtNombres.setEditable(habilitar);
        txtApellidoPaterno.setEditable(habilitar);
        txtApellidoMaterno.setEditable(habilitar);
        txtDni.setEditable(habilitar);
        txtNacionalidad.setEditable(habilitar);
        txtDireccion.setEditable(habilitar);
        comboDeptos.setEnabled(habilitar);
        comboProvincias.setEnabled(habilitar);
        comboDistrito.setEnabled(habilitar);
        txtTel.setEditable(habilitar);
        txtCelular.setEditable(habilitar);
        txtEmail.setEditable(habilitar);
        txtOcupacion.setEditable(habilitar);
        txtAntecedentes.setEditable(habilitar);
        txtRecomendado.setEditable(habilitar);
        comboGenero.setEnabled(habilitar);
        comboGrupo.setEnabled(habilitar);
        btnCambiarFoto.setEnabled(habilitar);
        btnEliminarFoto.setEnabled(habilitar);
        txtFechaNac.setEnabled(habilitar);
        txtFechaAlta.setEnabled(habilitar);

        if (habilitar == true) {
            txtNombres.requestFocus();
            txtNombres.selectAll();
        }
        if (habilitar == false) {
            btnModificar.setText("Modificar datos");
        } else {
            btnModificar.setText("Guardar cambios");
        }

    }

    /*
     * Método que carga una foto adaptándola al tamanho del label
     */
    public void cargarFoto(Image fotoPaciente) {
        //ImageIcon imagenes=new ImageIcon();
        //imagenes=new ImageIcon(foto);
        Icon icono = new ImageIcon(fotoPaciente.getScaledInstance(lblFoto.getWidth(), lblFoto.getHeight(), Image.SCALE_DEFAULT));
        lblFoto.setIcon(icono);
    }


    /*
     * Método que limpia los datos de la tabla
     */
    

    public boolean camposObligatorios() {
        //boolean registrar=true;

        if (validar.esVacio(
                txtNombres.getText())) {
            JOptionPane.showMessageDialog(this, "Debe ingresar un nombre", "Campo obligatorio", JOptionPane.ERROR_MESSAGE);
            txtNombres.requestFocus();
            return false;
        }
        if (validar.esVacio(txtApellidoPaterno.getText())) {
            JOptionPane.showMessageDialog(this, "Debe ingresar apellidos", "Campo obligatorio", JOptionPane.ERROR_MESSAGE);
            txtApellidoPaterno.requestFocus();
            return false;
        }



        if (validar.esVacio(txtAntecedentes.getText())) {
            JOptionPane.showMessageDialog(this, "Debe ingresar Antecedentes", "Campo obligatorio", JOptionPane.ERROR_MESSAGE);
            txtAntecedentes.requestFocus();
            return false;
        }




        return true;


    }
    
    
    

    public void cargarComboDeptos() {
        ControlUbigeo control = new ControlUbigeo();
        ArrayList<ArrayList> listadoDeptos = control.listarDeptos();

        for (int i = 0; i < listadoDeptos.size(); i++) {
            comboDeptos.addItem(listadoDeptos.get(i).get(1).toString());


        }
    }

    public void cargarComboProvincias(int cod) {

        ControlUbigeo control = new ControlUbigeo();
        ArrayList<ArrayList> listadoProv = control.listarProvincias(cod + 1);

        for (int i = 0; i < listadoProv.size(); i++) {
            comboProvincias.addItem(listadoProv.get(i).get(0).toString());


        }
    }

    public void cargarComboDistritos(int codDepto, int codProv) {
        ControlUbigeo control = new ControlUbigeo();
        ArrayList<ArrayList> listadoDist = control.listarDistritos(codDepto + 1, codProv + 1);

        for (int i = 0; i < listadoDist.size(); i++) {
            comboDistrito.addItem(listadoDist.get(i).get(0).toString());


        }

    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {

                //Look and feel NimROD
                /*
                 * try { UIManager.setLookAndFeel(new
                 * com.nilo.plaf.nimrod.NimRODLookAndFeel()); } catch
                 * (UnsupportedLookAndFeelException ex) {
                 * Logger.getLogger(dsad.class.getName()).log(Level.SEVERE,
                 * null, ex);
                }
                 */

                //Look and feel Nimbus (MAC)
                /*
                 * for(UIManager.LookAndFeelInfo
                 * laf:UIManager.getInstalledLookAndFeels()){
                 * if("Nimbus".equals(laf.getName())) try {
                 * UIManager.setLookAndFeel(laf.getClassName()); } catch
                 * (Exception ex) { }
                 }
                 */

                //Look and feel del Sistema
              /*
                 * try{
                 * UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                 * }catch(Exception e) { System.out.println(e); //best to do
                 * nothing here
                }
                 */

                Visual.aspectoMac();
                new probando().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCambiarFoto;
    private javax.swing.JButton btnConsulta;
    private javax.swing.JButton btnEliminarFoto;
    private javax.swing.JButton btnEliminarPaciente;
    private javax.swing.JButton btnModificar;
    private javax.swing.JButton btnReservarCita;
    private javax.swing.JButton btnVerOdontograma;
    private javax.swing.JComboBox comboDeptos;
    private javax.swing.JComboBox comboDistrito;
    private javax.swing.JComboBox comboGenero;
    private javax.swing.JComboBox comboGrupo;
    private javax.swing.JComboBox comboProvincias;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel lblCodPaciente1;
    private javax.swing.JLabel lblFoto;
    private javax.swing.JPanel panelFoto1;
    private javax.swing.JPanel panelPaciente;
    private javax.swing.JTextArea txtAntecedentes;
    private javax.swing.JTextField txtApellidoMaterno;
    private javax.swing.JTextField txtApellidoPaterno;
    private javax.swing.JTextField txtCelular;
    private javax.swing.JTextField txtCodigoPaciente;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtDni;
    private javax.swing.JTextField txtEdad;
    private javax.swing.JTextField txtEmail;
    private datechooser.beans.DateChooserCombo txtFechaAlta;
    private datechooser.beans.DateChooserCombo txtFechaNac;
    private javax.swing.JTextField txtNacionalidad;
    private javax.swing.JTextField txtNombres;
    private javax.swing.JTextField txtOcupacion;
    private javax.swing.JTextField txtRecomendado;
    private javax.swing.JTextField txtTel;
    // End of variables declaration//GEN-END:variables
}
